﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace TS_XY_Train_Repaire.UserCon.Locomotive.TrainRepair.Work.Fittings
{
    public partial class uc_Locomotive_TrainRepair_Work_Fittings_DownTrain_DepList_ManaForm : DevExpress.XtraEditors.XtraForm
    {
        public string _LoadType = "";
        public string _LoadBMWID = "";
        public string _LoadTDID = "";
        public string _LoadTDName = "";
        public string _LoadTLName = "";
        public string _LoadNum = "";
        public uc_Locomotive_TrainRepair_Work_Fittings_DownTrain_DepList_ManaForm()
        {
            InitializeComponent();
        }

        private void uc_Locomotive_TrainRepair_Work_Fittings_DownTrain_DepList_ManaForm_Load(object sender, EventArgs e)
        {
            string strSQL = "select f_id as f_depid,f_name as f_depname from TS_S_T_P_Department where f_id in (select f_depid from TS_S_T_B_WorkMain_Dispatcher where f_del=0 and f_type in (1,2))";
            SqlConnection conn = new SqlConnection(TS_Win_Class.GetSQlConnStr());
            conn.Open();
            SqlCommand comm = new SqlCommand(strSQL, conn);
            SqlDataReader read = comm.ExecuteReader();
            while (read.Read())
            {
                RadioButton _cb = new RadioButton();
                _cb.Name = "cb_D_02_" + read["f_depid"].ToString();
                _cb.Text = read["f_depname"].ToString();
                _cb.Width = 100;
                _cb.Padding = new System.Windows.Forms.Padding(0);
                _cb.Tag = read["f_depid"].ToString();
                _cb.Margin = new Padding(0);
                flp_Main.Controls.Add(_cb);
            }
            read.Close();
            read.Dispose();
            comm.Dispose();
            conn.Close();
            conn.Dispose();
        }

        private void bt_Sure_Click(object sender, EventArgs e)
        {
            string _str = "";
            string _strDepName = "";
            string _itID = TS_Win_Class.GetSQlFieldValue("select f_trainid from TS_TR_BU_Work_Main where f_id=" + _LoadBMWID, "f_trainid");
            RadioButton _cb = new RadioButton();
            foreach (Control _cl in flp_Main.Controls)
            {
                _cb = (RadioButton)_cl;
                if (_cb.Checked)
                {
                    _str = _cb.Tag.ToString();
                    _strDepName = _cb.Text;
                }
            }
            if (_str.Length == 0)
            {
                MessageBox.Show("没有指定有效的接收部门！");
            }
            else
            {
                string strSQL = "";
                for (int i = 0; i < Convert.ToInt32(_LoadNum); i++)
                {
                    strSQL = "insert into TS_TR_TM_Loco_Fittings_Work (f_fid,f_name,f_tdid,f_ftid,f_mapid,f_depid,f_itid,f_bmwid,f_itname,f_stuffid0,f_type) values(-1,'"+_LoadTDName+"',"+_LoadTDID+",-1,-1,"+_str+","+_itID+","+_LoadBMWID+",'"+_LoadTLName+"',"+TS_Win_Locomotive_MainForm.pUserInfoMain.GuId+","+_LoadType+")";
                    string _ID = TS_Win_Class.MySqlComGetID(strSQL);
                    strSQL = "insert into TS_S_T_P_Voice_Announce(f_vid,f_tablename,f_string,f_funcid,f_type,f_workerid) values(" + _ID + ",'TS_TR_TM_Loco_Fittings_Work','机车号：" + _LoadTLName + "有一个" + _LoadTDName + "下车，请工班" + _strDepName + "去作业！'," + _str + ",2," + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ")";
                    TS_Win_Class.MySqlCom(strSQL);
                }
                    this.DialogResult = DialogResult.OK;
            }
        }

        private void bt_Exit_Click(object sender, EventArgs e)
        {
            this.DialogResult=DialogResult.Cancel;
        }
    }
}